

var businessLogic = require('../../../utils/NetWork/Model/NewsbusinessLogic.js')
var WxParse = require('../../../utils/Component/wxParse/wxParse.js');
var common = require('../../../utils/common.js')
var orgid = common.getStorageSync("orgid")
var userid = common.getStorageSync("userid")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    post_title: [],
    banner_url:[],
    num:1
  },
   onLoad: function (options) {
     var ryid = options.id;
     var scrollHeight = scrollHeight;
     wx.getSystemInfo({
       success: function (res) {
         scrollHeight = res.windowHeight
       }
     });
     this.setData({
       scrollHeight: scrollHeight,
     });

    this.rytemp(ryid);
    this.news();
  }, 
   bindDownLoad: function () {
     if (this.data.lenpage > this.data.num) {
       var di = this.data.num;
       var di = di + 1;
       this.setData({
         num: di
       });
     } else {
       common.showToast("加载全部", "loading");
     }
     //common.showToast("到底了", "loading");

   },
  //2.1.3新闻详情内容
  rytemp: function (ryid) {
    let params = { "id":ryid, "orgid":orgid, "userid": userid  };
    //第三步 调用接口
    businessLogic.NewsInfo(params, (res) => {
     
      //第五步 把获取的值，传入data
      this.setData({
        post_title: res
      });
       var article = res.content;
      var that = this;
      WxParse.wxParse('article', 'html', article, that, 5); 
    });
  }, 

//2.1.2新闻列表
  news: function () {
    common.showToast("加载中", "loading");
    // 第二步 传参
    let params = { "page": this.data.num, "num": 5, "orgid": orgid, "userid": userid, "searchField": "orgid", "searchValue": orgid, }
    //第三步 调用接口
    businessLogic.NewsList(params, (res) => {
      //第五步 把获取的值，传入data
      var n = [];
      for (var i = 0; i < res.infos.length; i++) {
        if (res.infos[i].onclick > 999999) {
          // n[i] = Math.round((res.infos[i].onclick / 100000) * 100) / 100;
          res.infos[i].onclick = 999999 + "+";
        } else {
          res.infos[i].onclick = res.infos[i].onclick + "次";
        }
      }
      var bbb = this.data.banner_url;
      for (var a = 0; a < res.infos.length; a++) {
        bbb.push(res.infos[a]);
      } 
      this.setData({
        banner_url: bbb,
        lenpage: res.page.pages
      });

    });

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '自定义转发标题',
      path: '/page/user?id=123',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  collect: function () {
    this.setData({
      like: !this.data.like
    })
  },
  newsDetailPic: function (event) {
    //跳转
    wx.navigateTo({
      url: "../newsDetailPic/newsDetailPic?id=" + event.currentTarget.dataset.id
    });
  },

})